<!-- 我的-分享好友 -->
<template>
	<view class="page-box">
		<view class="box" v-if="shareUrl">
			<image @longtap="longtap" style="width: 640rpx;" mode="widthFix" :src="shareUrl"></image>
			<text style="margin-top: 40rpx;color: #0F0F0F;font-size: 34rpx;font-weight: bold;">长按可保存到手机</text>
		</view>
	</view>
</template>

<script>
	import {
		postServiceStatus,
		postHeadUpload,
		getShareUrl
	} from '@/api/user.js'
	export default {
		components: {},
		data() {
			return {
				shareUrl: ''
			};
		},
		mounted() {
			uni.showLoading({
				title: '正在加载中'
			});
			getShareUrl().then(res => {
				this.shareUrl = res.data.shareUrl
			}).finally(() => {
				uni.hideLoading();
			})
		},
		onLoad() {},
		methods: {
			//保存图片
			longtap() {
				return
				uni.showActionSheet({
					itemList: ['保存图片'],
					success: () => {
						uni.downloadFile({
							url: this.shareUrl,
							success: (res) => {
								if (res.statusCode === 200) {
									uni.saveImageToPhotosAlbum({
										filePath: res.tempFilePath,
										success: function() {
											uni.showToast({
												duration: 5000,
												title: "保存成功"
											});
										},
										fail: function() {
											uni.showToast({
												duration: 5000,
												title: "保存失败，请稍后重试",
												icon: "none"
											});
										}
									});
								}
							}
						})
					}
				})
				return
				uni.showModal({
					title: '保存图片',
					content: '是否保存当前图片？',
					success: (res) => {
						if (res.confirm) {
							uni.downloadFile({
								url: this.shareUrl,
								success: (res) => {
									if (res.statusCode === 200) {
										uni.saveImageToPhotosAlbum({
											filePath: res.tempFilePath,
											success: function() {
												uni.showToast({
													duration: 5000,
													title: "保存成功",
													duration: 2000
												});
											},
											fail: function() {
												uni.showToast({
													duration: 5000,
													title: "保存失败，请稍后重试",
													icon: "none"
												});
											}
										});
									}
								}
							})
						} else if (res.cancel) {
							// uni.showToast({
							// duration: 5000,
							// 	title: "你取消了该操作",
							// 	icon:'none',
							// 	duration: 2000
							// });
						}
					}
				});
			}
		}
	}
</script>

<style lang="scss">
	.page-box {
		position: relative;
		box-sizing: border-box;
		background: linear-gradient(180deg, rgba(238, 212, 215, 0.8) 0%, rgba(202, 191, 192, 0) 100%);
		min-height: 100vh;

	}

	.box {
		width: 100%;
		padding: 20rpx;
		box-sizing: border-box;
		position: absolute;
		top: 0;
		display: flex;
		flex-direction: column;
		align-items: center;
	}
</style>